import Vue from 'vue'
import VueRouter from 'vue-router'
import axios from 'axios'

import * as i18n from './i18n'
import App from './App'
import NotFound from './views/NotFound'
import './assets/css/index.css'
axios.defaults.timeout = 10 * 1000

Vue.config.ignoredElements = [
  /^yt-/
]


const router = new VueRouter({
  mode: 'history',
  routes: [
    {
      path: '/',
      component: () => import('./layout'),
      children: [
        { path: '', name: 'home', component: () => import('./views/Home') },
        { path: 'stylegen', name: 'stylegen', component: () => import('./views/StyleGenerator') },
        { path: 'help', name: 'help', component: () => import('./views/Help') },
        { path: 'plugins', name: 'plugins', component: () => import('./views/Plugins') },
        { path: 'music', component: () => import('./views/Music'),
          children: [
            { path: '', name: 'music', component: () => import('./views/Music/MusicList') },
            { path: 'config', name: 'config', component: () => import('./views/Music/Config') },
            { path: 'list', name: 'list', component: () => import('./views/Music/MusicList') },
            { path: 'data', name: 'data', component: () => import('./views/Music/MusicData') },
          ]
        },
      ]
    },
    {
      path: '/index',
      name: 'index',
      component: () => import('./views/index'),
      props(route) {
        let user = route.query.user ? JSON.parse(route.query.user) : null
        return { user }
      }
    },
    // 盲盒姬旧版
    {
      path: '/gift/:roomKeyValue',
      name: 'gift',
      component: () => import('./views/GiftCount'),
      props(route) {
        let roomKeyValue = route.params.roomKeyValue
        return { roomKeyValue, strConfig: route.query }
      }
    },
    // 盲盒姬新版
    {
      path: '/giftCount',
      name: 'giftCount',
      component: () => import('./views/GiftCountNew'),
    },
    {
      path: '/gift2/:roomKeyValue',
      name: 'gift2',
      component: () => import('./views/GiftCountBeautiful'),
      props(route) {
        let roomKeyValue = route.params.roomKeyValue
        return { roomKeyValue, strConfig: route.query }
      }
    },
    {
      path: '/gift3/:roomKeyValue',
      name: 'gift3',
      component: () => import('./views/GiftCountBeautiful2'),
      props(route) {
        let roomKeyValue = route.params.roomKeyValue
        return { roomKeyValue, strConfig: route.query }
      }
    },
    // 礼物排行榜
    {
      path: '/giftRanking',
      name: 'giftRanking',
      component: () => import('./views/GiftRanking'),
    },
    // 大声密谋
    {
      path: '/loud',
      name: 'loud',
      component: () => import('./views/LoudConspiracy'),
    },
    // 弹幕助手
    {
      path: '/danmuHelper',
      name: 'danmuHelper',
      component: () => import('./views/DanmuHelper'),
    },
    {
      path: '/room/test',
      name: 'test_room',
      component: () => import('./views/Room'),
      props: route => ({ strConfig: route.query })
    },
    {
      path: '/room/:roomKeyValue',
      name: 'room',
      component: () => import('./views/Room'),
      props(route) {
        let roomKeyType = parseInt(route.query.roomKeyType) || 1
        if (roomKeyType < 1 || roomKeyType > 2) {
          roomKeyType = 1
        }

        let roomKeyValue = route.params.roomKeyValue
        if (roomKeyType === 1) {
          roomKeyValue = parseInt(roomKeyValue) || null
        } else {
          roomKeyValue = roomKeyValue || null
        }
        return { roomKeyType, roomKeyValue, strConfig: route.query }
      }
    },
    { path: '*', component: NotFound }
  ]
})

new Vue({
  render: h => h(App),
  router,
  i18n: i18n.i18n
}).$mount('#app')
